package com.ruoyi.client.controller;

import com.ruoyi.client.domain.vo.TagsTreeVo;
import com.ruoyi.client.domain.entity.BlogTagsCategory;
import com.ruoyi.client.service.IBlogTagsCategoryService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.common.web.core.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("client/user/tag-category")
public class BlogTagCategoryController extends BaseController {
    @Autowired
    IBlogTagsCategoryService tagsCategoryService;

    //用户端
    /**
     * 获取tree结构tags
     * @return
     */
    @GetMapping("tree")
    public R<List<TagsTreeVo>> tree(){
        List<TagsTreeVo> result = tagsCategoryService.tree();
        return R.ok(result);
    }

    //管理端
    @GetMapping("list")
    public TableDataInfo<BlogTagsCategory> list(PageQuery query){
        TableDataInfo<BlogTagsCategory> result = tagsCategoryService.selectBlogTagCategoryList(query);
        return result;
    }
    @PostMapping
    public R add(@RequestBody BlogTagsCategory tagsCategory){
        boolean result = tagsCategoryService.addBlogTagCategory(tagsCategory);
        return toAjax(result);
    }
    @GetMapping("/{id}")
    public R<BlogTagsCategory> getInfor(@PathVariable Long id){
        BlogTagsCategory tagsCategory = tagsCategoryService.getById(id);
        return R.ok(tagsCategory);
    }
    @PutMapping
    public R<Void> update(@RequestBody BlogTagsCategory blogTagsCategory){
        boolean b = tagsCategoryService.updateTagCategory(blogTagsCategory);
        return toAjax(b);
    }
    @DeleteMapping("/{ids}")
    public R<Void> delete(@PathVariable Long[] ids){
        boolean b = tagsCategoryService.deleteTagCategory(ids);
        return toAjax(b);
    }
    @GetMapping("optionselect")
    public R<List<BlogTagsCategory>> optionselect(){
        List<BlogTagsCategory> list = tagsCategoryService.list();
        return R.ok(list);
    }
}
